package com.repository.controller;

import com.repository.common.Result;
import com.repository.entity.ProductShipment;
import com.repository.service.ProductShipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 待出库表(ProductShipment)表控制层
 *
 * @author makejava
 * @since 2024-07-14 17:38:15
 */
@RestController
@RequestMapping("/productShipment")
@Slf4j
public class ProductShipmentController {
    /**
     * 服务对象
     */
    @Resource
    private ProductShipmentService productShipmentService;

    /**
     * 分页查询
     *
     * @param productShipment 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
/*    @GetMapping
    public ResponseEntity<Page<ProductShipment>> queryByPage(ProductShipment productShipment, PageRequest pageRequest) {
        return ResponseEntity.ok(this.productShipmentService.queryByPage(productShipment, pageRequest));
    }*/

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Result<ProductShipment> queryById(@PathVariable("id") String id) {
        log.info("通过主键查询单条数据:{}", id);
        if (id == null || id.isEmpty()){
            return Result.fali("id不能为空");
        }
        return Result.ok(this.productShipmentService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param productShipment 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ProductShipment> add(ProductShipment productShipment) {
        return ResponseEntity.ok(this.productShipmentService.insert(productShipment));
    }

    /**
     * 编辑数据
     *
     * @param productShipment 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ProductShipment> edit(ProductShipment productShipment) {
        return ResponseEntity.ok(this.productShipmentService.update(productShipment));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String id) {
        return ResponseEntity.ok(this.productShipmentService.deleteById(id));
    }

}

